package com.cs.study.homework._0222;

public class Demo3 {
    public static void main(String[] args) {
        Shape shape;
        shape = new Rectangle(10, 20);
        shape.getPerimeter();
        shape.getArea();

        System.out.println("---------------");

        shape = new Circle(10);
        shape.getPerimeter();
        shape.getArea();
    }
}

abstract class Shape {
    public abstract void getPerimeter();

    public abstract void getArea();
}

class Rectangle extends Shape {
    private double shortSideLength;
    //定义长边
    private double longSideLength;

    public Rectangle(double shortSideLength, double longSideLength) {
        this.shortSideLength = shortSideLength;
        this.longSideLength = longSideLength;
    }

    @Override
    public void getPerimeter() {
        double perimeter = shortSideLength * 2 + longSideLength * 2;
        System.out.println("长方形周长 = " + perimeter);
    }

    @Override
    public void getArea() {
        double area = shortSideLength * longSideLength;
        System.out.println("长方形面积 = " + area);
    }
}

class Circle extends Shape {
    double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public void getPerimeter() {
        double perimeter = 2 * radius * Math.PI;
        System.out.println("圆周长 = " + perimeter);
    }

    @Override
    public void getArea() {
        double area = radius * radius * Math.PI;
        System.out.println("圆面积 = " + area);
    }
}
